#ifndef RTTIMERLOOP_H
#define RTTIMERLOOP_H

#include "RtJob.h"

/** A real-time timer loop based on win32 timers.

\ingroup RtCore

After calling arm() a timer thread is launched which
executes [i.e., calls the exec() function] of the loop
and all its child-jobs. The loop is repetitive
with the period given in ms.

The timer is realized by means of the timeSetEvent() and
timeKillEvent() functions of the windows SDK.

*/
class RTLAB_BASE_EXPORT RtTimerLoop : public RtLoop
{
	Q_OBJECT

	/** The repetition period in ms.
	*/
	Q_PROPERTY(uint period READ period WRITE setPeriod)

protected:

	typedef win32timer<RtTimerLoop> my_timer_t;
	friend class my_timer_t;

	my_timer_t timer_;
	unsigned int period_;

	virtual bool arm_();
	virtual void disarm_();

	// timer callback function
	void timerProc() { exec(); }

public:
	Q_INVOKABLE RtTimerLoop(const QString& name);
	virtual ~RtTimerLoop(void);

	unsigned int period() const { return period_; }
	void setPeriod(unsigned int p);
};

#endif // RTTIMERLOOP_H
